<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8" />
	<title>千郡医疗</title>
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<meta name="format-detection" content="telephone=no" />
	<link rel="stylesheet" th:href="@{/weixin/css/style.css}" />
	<link rel="stylesheet" th:href="@{/weixin/css/dropload.css}" />
	<link rel="stylesheet" th:href="@{/weixin/css/weui.min.css}" />
	<script type="text/javascript"  th:src="@{/weixin/js/adaptive.js}"></script>
	<script type="text/javascript"  th:src="@{/weixin/js/fastclick.min.js}"></script>
	<script type="text/javascript"  th:src="@{/weixin/js/zepto.min.js}"></script>
	<script type="text/javascript"  th:src="@{/weixin/js/dropload.min.js}"></script>
	<script type="text/javascript" th:src="@{/weixin/js/weui.min.js}"></script>
	<script type="text/javascript" th:src="@{/assets/js/plugins/moment/moment.js}"></script>
	<style>
	.noneBorder{
		border: none;
	}
	body{font-size: initial !important;}
	</style>
</head>
<body>
		<section class="recordBox wrapper">
		<div class="box-h recordDate">
			<ul class="dataList flex">
				<li class="box-h">
					<span class="name">开始时间</span>
					<p id="beginDate" class="date flex" th:text="${beginDate}"></p>
				</li>
				<li class="box-h">
					<span class="name">结束时间</span>
					<p id="endDate" class="date flex" th:text="${endDate}"></p>
				</li>
			</ul>
			<a href="javascript:toHref();" class="btn">确定</a>
		</div>
		<div class="ktab">
			<table>
				<thead>
					<tr>
						<td>代理名称</td>
						<td>日期</td>
						<td>K值</td>
					</tr>
				</thead>
				<tbody id="context">
				</tbody>
			</table>
		</div>
	</section>
	
	<script  th:inline="JavaScript">
	var query = {'recommDistributorId':[[${recommDistributorId}]],'distributorId':[[${distributorId}]],'beginDate':[[${beginDate}]],'endDate':[[${endDate}]]};
	</script>
	
	<script type="text/javascript">
	/*<![CDATA[*/
	           
    function toHref(){
    	
		var listUrl = "/qianjun/weixin/order/toRebateBook?distributorId=" + query.distributorId + "&recommDistributorId=" + query.recommDistributorId;	
			
    	var beginDate = $("#beginDate").text();
    	var endDate = $("#endDate").text();
    	
    	if(beginDate){
    		listUrl += "&beginDate=" + beginDate;
    	}
    	
    	if(endDate){
    		listUrl += "&endDate=" + endDate;
    	}	
    	
    	window.location.href = listUrl;
    }	           

$(function(){	  	           
	$("#beginDate").click(function(){
			weui.datePicker({
				start: '2017-07-01',
				end: moment().add(30,"days").format("YYYY-MM-DD"),
		        onConfirm: function onConfirm(result) {
		        	
		        	var d = result[0].value + "-" + (result[1].value < 10 ? ("0" + result[1].value) : result[1].value) + "-" + (result[2].value < 10 ? ("0" + result[2].value) : result[2].value);
		        	
		        	//$("#date").val(moment(d).format("YYYY-MM-DD"));
		        	$("#beginDate").text(d);
		        	query["beginDate"] = d;
		        },
		        id: 'datePicker'
		    });
		});
		
		$("#endDate").click(function(){
			weui.datePicker({
		        start: '2017-07-01',
		        end: moment().add(30,"days").format("YYYY-MM-DD"),
		        onConfirm: function onConfirm(result) {
		        	var d = result[0].value + "-" + (result[1].value < 10 ? ("0" + result[1].value) : result[1].value) + "-" + (result[2].value < 10 ? ("0" + result[2].value) : result[2].value);
		        	//$("#date").val(moment(d).format("YYYY-MM-DD"));
		        	$("#endDate").text(d);
		        	query["endDate"] = d;
		        },
		        id: 'datePicker'
		    });
		});	           
         
		var page = 0;
 		$('.wrapper').dropload({
		    autoLoad : true,//自动加载
		    loadDownFn : function(me){
		      window.history.pushState(null, document.title, window.location.href); 
		        $.ajax({
		            type: 'GET',
		            url: "/qianjun/weixin/order/kValueList?page=" + page,
		            dataType: 'json',
		            data: query,
		            success: function(data){
		                if(data.content.length == 0){
		                    me.lock();
		                    me.noData();
		                    me.resetload();
		                    return;
		                }

				        var result = '';
		                for(var i=0; i< data.content.length; i++){
		                  result += '<tr><td>' + data.content[i][0] + '</td><td>' + data.content[i][1] + '</td><td>' + data.content[i][2] + '</td></tr>';
		                }
		                $('#context').append(result);
		                page++;
		                me.resetload(); 
		            },
		            error: function(xhr, type){
		                me.resetload();
		            }
		        });
		    }
		}); 
});
	 /*]]>*/
	</script>
</body>
</html>